package com.yeqian.controller;

import com.yeqian.entity.PageResult;
import com.yeqian.entity.QueryPageBean;
import com.yeqian.entity.Result;
import com.yeqian.pojo.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author : yeqian
 * @Date : 2020/12/31 23:32
 * 标签控制器
 */
@RestController
@RequestMapping("/tag")
@Api(description = "标签控制器")
public class TagController extends BaseController {



    /**
     * 饼状图
     *
     * @param
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/16 22:50
     */
    @PostMapping("/getPieReport")
    @ApiOperation("查询标签总数量")
    public Result getPieReport() {
        //查询各标签占比
        List<Map<String, Object>> count = tagService.getReport();
        return new Result(true, "获取数据", count);
    }

    /**
     * 查询标签总数量
     *
     * @param
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/16 11:32
     */
    @GetMapping("/getTagCount")
    @ApiOperation("查询标签总数量")
    public Result getTagCount() {
        Integer tagCount = tagService.getTagCount();
        return new Result(true, "查询标签总数量成功", tagCount);
    }

    /**
     * 查询所有标签
     *
     * @param
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/1 21:32
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有标签")
    public Result listAll() {
        List<String> tags = tagService.listAll();
        return new Result(true, "查询所有标签成功", tags);
    }

    /**
     * 删除标签
     *
     * @param id
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/1 17:16
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除标签")
    public Result deleteTag(@PathVariable("id") Integer id) {
        tagService.deleteTag(id);
        return new Result(true, "删除标签成功");
    }

    /**
     * 编辑标签
     *
     * @param tag
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/1 16:42
     */
    @PutMapping
    @ApiOperation("编辑标签")
    public Result update(@RequestBody Tag tag) {
        tagService.updateTag(tag);
        return new Result(true, "编辑标签成功");
    }

    /**
     * 根据主键获取标签
     *
     * @param id
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/1 16:20
     */
    @GetMapping("/{id}")
    public Result getTag(@PathVariable("id") Integer id) {
        Tag tag = tagService.getTag(id);
        return new Result(true, "根据主键获取标签成功", tag);
    }

    /**
     * 新增标签
     *
     * @param
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2021/1/1 11:54
     */
    @PostMapping
    @ApiOperation("新增标签")
    public Result saveTag(@RequestBody Tag tag) {
        tagService.saveTag(tag);
        return new Result(true, "新增标签成功");
    }

    /**
     * 标签分页查询
     *
     * @param queryPageBean
     * @return com.yeqian.entity.Result
     * @author yeqian
     * @date 2020/12/31 23:36
     */
    @PostMapping("/search")
    @ApiOperation("标签分页查询")
    public Result listQueryPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = tagService.listQueryPage(queryPageBean);
        return new Result(true, "标签分页查询成功", pageResult);
    }
}
